Skip to content

Gate Logic

A technique for implementing Boolean functions using logic gates

Logic Gates

  • Elementary: NAND, AND, OR, NOT
  • Composite: MUX, ADDER

NAND

Function:

python
def NAND(a, b):
    return (a == 1 and b == 1)? 0 : 1

Truth Table:

xyNAND
001
011
101
110

AND

python
def AND(a, b):
    return (a == 1 and b == 1)

OR

python
def OR(a, b):
    return (a == 1 or b == 1)

NOT

python
def NOT(a):
    return not a

Composite Gates

Interface

  • Answer the question of "what"
  • Abstraction for the user
  • Unique for each functionality

Implementation

  • Answer the question of "how"
  • For the engineers
  • Multiple ways to implement

MUX (Multiplexer)

Also called data selector If seg is 0, out = a, else out = b

Z=(A¬S0)(BS0)

**Diagram**

HDL

HDL
/** 
 * Multiplexor:
 * if (sel = 0) out = a, else out = b
 */
CHIP Mux {
    IN a, b, sel;
    OUT out;

    PARTS:
    Not (in=sel, out=Notsel);
    And (a=a, b=Notsel, out=aAndNotsel);
    And (a=sel, b=b, out=bAndsel);
    Or (a=aAndNotsel, b=bAndsel, out=out);
}

DMUX (Demultiplexer)

Demultiplexers take one data input and a number of selection inputs, and they have several outputs.

If the input is always true, demultiplexers can act as binary decoders, selecting the bits of corresponding output.

Expression

A=(I¬S)B=(IS)

Truth Table

InSelab
0000
0100
1010
1101

**Diagram**

HDL

HDL
/**
 * Demultiplexor:
 * [a, b] = [in, 0] if sel = 0
 *          [0, in] if sel = 1
 */
CHIP DMux {
    IN in, sel;
    OUT a, b;

    PARTS:
    Not (in=sel, out=Notsel);
    And (a=in, b=Notsel, out=a);
    And (a=in, b=sel, out=b);
}